package cn.wolfcode.crm.util;

import cn.wolfcode.crm.domain.Employee;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.security.Security;

public class UserContext {
    public static Employee getCurrentuser(){
        Subject subject = SecurityUtils.getSubject();
        return (Employee) subject.getPrincipal();
    }
    //获取请求request
    public static HttpServletRequest getRequest(){
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.getRequestAttributes())).getRequest();
        return request;
    }
    //获取session
    public static Session getSession(){
        return SecurityUtils.getSubject().getSession();
    }
}
